package org.example.Thread01;

public class Dome_Thread07 {
    public static void main(String[] args) throws InterruptedException {
        Counter counter=new Counter();
        //创建两个线程对一个变量进行累加
        Thread t1 = new Thread(()->{
            for(int i=0;i<50000;i++){
                counter.increase();
            }
        });
        Thread t2 = new Thread(()->{
            for(int i=0;i<50000;i++){
                counter.increase();
            }
        });
        //启动线程
        t1.start();
        t2.start();
        //等待线程结束
        t1.join();
        t2.join();
        System.out.println(counter.count);
    }
}
class Counter{
    public int count=0;
    public void increase(){
        count++;
    }
}
